//--------------------------------------------------------------------------------
// This file is a portion of the D2D1Renderer.  It is distributed
// under the MIT License, available in the root of this distribution and 
// at the following URL:
//
// http://www.opensource.org/licenses/mit-license.php
//
// Copyright (c) Mirco Timmermann
//
//--------------------------------------------------------------------------------
#include "Bitmap.h"


namespace D2 {

Bitmap::Bitmap(std::wstring filename) { //TODO: D2D1Renderer.Get()
	_image = new Image(filename);

	_width = (int)_image->getWidth();
	_height = (int)_image->getHeight();

	_showBorder = false;
}

Bitmap::~Bitmap(void) {
	delete _image;
}

bool Bitmap::Draw(Direct2DContext* ctx, D2D1::Matrix3x2F* mtx) {
	if(_image != 0) {
		ctx->drawImage(_image, 0, 0);
	}

	if(_showBorder) {
		ctx->lineWidth = 2;
		ctx->SetStrokeStyle(0.0f, 0.0f, 0.0f);
		ctx->rect(0, 0, _width, _height);
		ctx->stroke();
	}
	
	return true;
}

void Bitmap::ScaleByDimension(float size) {
	float scale = 1;
	if(_width > _height) {
		scale = size/_width;
	} else {
		scale = size/_height;
	}

	_scaleX = scale;
	_scaleY = scale;
}

}